package org.brisling.oa;

import java.util.List;

import org.brisling.sysman.domain.Permissions;
import org.brisling.sysman.queryService.QueryPermissionService;
import org.brisling.sysman.service.PermissionService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:config/applicationContext.xml",
						"classpath*:config/sysmanContext.xml"})
public class testInsertBut {

	@Autowired
	private PermissionService ps;
	@Autowired
	private QueryPermissionService qps;
	
	@Test
	public void test() {
		String names[] = {"信息设备维修", "信息设备采购"};
//		addButtons("基建付款", 3L);
		for(String name:names){
			addButtons(name, 3L);
		}
	}

	private void addButtons(String name, Long type){
		String sql = "select * from sysman_permission where name = '"+ name + "'";
		if(name == null || name.trim().length() <= 0){
			return;
		}
		List<Permissions> lists = qps.getAllBySql(sql);
		if(lists.size() == 1){
			ps.autoGeneratePermissions(lists.get(0).getId(), type);
		}
	}
}
